/**
 * 功能描述 列表
 */

define(function (require, exports, module) {
	var Component = require("grid");
	var Dialog = require("dialog");
	
	var fetchProperties = require("../constant/fetchProperties");
	var gridDataStatusFormat = require("../store/gridDataStatusFormat");
	var queryChargeDataSvc = require("../store/queryChargeDataSvc");
	var gridEvents = require("../handler/gridEvents");
	
    var instance = {
        initComponent : function (params, widget) {
            var component = new Component({
            	parentNode : ".J-grid",	
            	url : "api/signupcharge/queryplanitem",
            	autoRender : false,
				params : function(){
					var subnav = widget.get("subnav");
					var obj = {
                			pkServicePoint : widget.get("subnav").getValue("servicePoint"),
                			startDate : widget.get("subnav").getValue("startDate").start,
                			startDateEnd : widget.get("subnav").getValue("startDate").end,
                			pkDestination : widget.get("subnav").getValue("destination"),
                			planStatus : widget.get("subnav").getValue("status")
                	};
	    			return obj;
				},
				model : {
				 columns  : [{
					 name : "year",
					 label : "年度",
					 format : "date",
					 formatparams : {
						mode : "YYYY"
					 }
				 },{
					 name : "desName",
					 label : "目的地"
				 },{
					 name : "startDate",
					 label : "开始日期",
					 format : "date",
				 },{
					 name : "endDate",
					 label : "结束日期",
					 format : "date"
				 },{
					 name : "signUpNumber",
					 label : "报名人数"
				 },{
					 name : "chargeNumber",
					 label : "已缴费人数"
				 },{
					 name : "status",
					 label : "状态",
					 format : function(value,row){
						 return gridDataStatusFormat.statusFormat(row);
					 }
				 },{
					 name : "operate",
					 label : "操作",
					 format:"button",
						formatparams:[{
								id:"charge",
								text:"收费",
								show:function(value,data){
									if(data.signUpNumber == data.chargeNumber||(data.status == "Review" && !data.isAdjustment)){
										return false;
									}else{
										return true;
									}
								},
							handler:function(index,data,rowEle){
								if(data.status == "Review" && !data.isAdjustment){
									Dialog.alert({
										title : "提示",
										content : "已经复核完成，无法继续收费！"
									});
									return false
									
								}
								if(data.signUpNumber == data.chargeNumber){
									Dialog.alert({
										title : "提示",
										content : "已经收费完成，等待复核！"
									});
									return false
								}
								widget.show([".J-form", ".J-editgrid"]).hide(".J-grid");
								widget.get("subnav").show(["save", "cancel"]).hide(["startDate", "destination", "status", "servicePoint"]);
								widget.get("form").setData(data);
								queryChargeDataSvc.queryChargeData(data, widget);
							}
						},{
							id:"review",
							text:"复核",
							show:function(value,data){
								if(data.isAdjustment||data.status == "Review"||data.status == "AdjustmentReview"||!(data.signUpNumber == data.chargeNumber||(data.status == "Review" && !data.isAdjustment))){
									return false;
								}else{
									return true;
								}
							},
							handler:function(index,data,rowEle){
								gridEvents.review(data, widget);
							}
						},{
							id:"AdjustmentReview",
							text:"调整复核",
							show:function(value,data){
								if(data.status != "AdjustmentReview"&&data.isAdjustment && (data.signUpNumber == data.chargeNumber||(data.status == "Review" && !data.isAdjustment))){
									return true;
								}else{
									return false;
								}
							},
							handler:function(index,data,rowEle){
								gridEvents.adjustment(data, widget);
							}
						},{
							key:"detail",
							text:"查看",
							handler:function(index,data,rowEle){
								widget.show([".J-form", ".J-detailgrid"]).hide(".J-grid");
								widget.get("form").setData(data);
								widget.get("subnav").show(["cancel"]).hide(["save","startDate", "destination", "status", "servicePoint"]);
								queryChargeDataSvc.queryChargeData(data, widget);
							}
						}]
				 }]
				}
            });
            widget.set("grid", component);
        }
    };
    module.exports = instance;
});
